package com.zeus.elasticsearch.configuration;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;

/**
 * @author 冯扬龙
 * @date 2022/5/2 23:13
 */
@Configuration
public class ESConfiguration extends AbstractElasticsearchConfiguration {

    @Value("${elasticSearch.host}")
    private String elasticSearch;

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(elasticSearch)
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
